using System;
using System.Collections.Generic;
using System.IO;
using System.Web;
namespace HKB.Web
{
	public class AdUploadFileComponent
	{
		private AdUploadFileComponent()
		{
		}
		public static List<AdUploadFile> GetAdUploadFileByLastAccess(string DirFileLocal, DateTime LastAccess, string SortExpression)
		{
			List<AdUploadFile> list = new List<AdUploadFile>();
			if (Directory.Exists(DirFileLocal))
			{
				string[] files = Directory.GetFiles(DirFileLocal);
				for (int i = 0; i < files.Length; i++)
				{
					string text = files[i];
					if (File.Exists(text))
					{
						FileInfo fileInfo = new FileInfo(text);
						if (LastAccess >= fileInfo.LastAccessTime)
						{
							string text2 = fileInfo.FullName;
							text2 = text2.Substring(text2.LastIndexOf("\\") + 1, text2.Length - text2.LastIndexOf("\\") - 1);
							string fileSize = fileInfo.Length.ToString() + "字节";
							string fileType = text2.Substring(text2.LastIndexOf(".") + 1, text2.Length - text2.LastIndexOf(".") - 1);
							string lastAccess = fileInfo.LastAccessTime.ToShortDateString();
							string fullName = fileInfo.FullName;
							AdBll adBll = new AdBll();
							string isWasteFile = "否";
							if (adBll.FindFileByFileName("http://" + HttpContext.Current.Request.Url.Host.ToString() + "/IMS_AD/UploadAdpic/" + text2))
							{
								isWasteFile = "是";
							}
							list.Add(new AdUploadFile(text2, fileSize, fileType, lastAccess, fullName, isWasteFile));
						}
					}
				}
			}
			list.Sort(new AdUploadFileComparer(SortExpression));
			return list;
		}
		public static void DelecteFiles(string ArrayFile)
		{
			string[] array = ArrayFile.Split(new char[]
			{
				','
			});
			for (int i = 0; i < array.Length; i++)
			{
				if (File.Exists(array[i]))
				{
					File.Delete(array[i]);
				}
			}
		}
		public static void DelecteFile(string FileLoacl)
		{
			if (File.Exists(FileLoacl))
			{
				File.Delete(FileLoacl);
			}
		}
	}
}
